package com.snailhd.scheduled;

import com.snailhd.crawler.CrawlerRealTimeStockDataExector;
import com.snailhd.dto.QueryStockListDTO;
import com.snailhd.entity.Stock;
import com.snailhd.entity.StockRealTime;
import com.snailhd.mapper.StockDayMapper;
import com.snailhd.mapper.StockMapper;
import com.snailhd.util.StocklUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时维护stock_day
 * @author hd
 * @date 2019-12-01 14:24
 */

@Slf4j
@Component
@JobHandler("stockDayMaintainScheduled")
public class StockDayMaintainScheduled extends IJobHandler {

    @Resource
    CrawlerRealTimeStockDataExector crawlerRealTimeStockDataExector;

    @Resource
    StockMapper stockMapper;

    @Resource
    StockDayMapper stockDayMapper;

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        log.info(StringUtils.center("stockDayMaintainSheduled start !!!",80,"*"));
        List<Stock> list = stockMapper.query(new QueryStockListDTO());
        List<StockRealTime> stockRealTimes = crawlerRealTimeStockDataExector.exec(StocklUtil.getSymbols(list));
        stockDayMapper.insertOrUpdate(stockRealTimes);
        log.info(StringUtils.center("stockDayMaintainSheduled end !!!",80,"*"));
        return SUCCESS;

    }
}
